
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

public class Monster extends Canvas implements Thing {

	private Strategy strategy;
		
	private Thing maze[][];
	
	private Pacman p;
	
	private int direction;
	
	private int x;
	
	private int y;
	
	private int oldX;
	
	private int oldY;
	
	private boolean behaviour;
	
	public Monster(int x, int y, Strategy s) {
		this.x = x;
		this.y = y;
		behaviour = true;
		strategy = s;
	}
    
	/**
	 * drawing of monster
	 */
	public void draw(Graphics g) {
    	g.setColor(Color.white);
        g.fillRect(oldX * 30, oldY * 30, 30, 30);
    	g.setColor(Color.DARK_GRAY);
		g.fillRoundRect(x * 30 + 0, y * 30 + 0, 30, 30, 20, 30);
		g.fillRect(x * 30 + 0, y * 30 + 10, 30, 20);
		g.setColor(Color.white);
		g.fillOval(x * 30 + 0,y * 30 + 25, 7, 7);
		g.fillOval(x * 30 + 8, y * 30 + 25, 7, 7);
		g.fillOval(x * 30 + 15, y * 30 + 25, 7, 7);
		g.fillOval(x * 30 + 22, y * 30 + 25, 7, 7);
		g.fillOval(x * 30 + 29, y * 30 + 25, 7, 7);
		g.setColor(Color.black);
 		g.fillArc(x * 30 + 6, y * 30 + 4, 20, 20, 0, 45);
 		g.fillArc(x * 30 + 5, y * 30 + 4, 20, 20, 135, 45);
		g.setColor(Color.red);
		g.fillOval(x * 30 + 8, y * 30 + 10, 4, 4);
		g.fillOval(x * 30 + 19, y * 30 + 10, 4, 4);
		oldX = x;
		oldY = y;
		move();
	}
    
	/**
	 * method of checking pacmans and monsters coordinates
	 * @param xP - pacmans coordinate
	 * @param yP - pacmans coordinate
	 * @return true - if pacmans and monsters coordinates are equal, false - else
	 */
    public boolean ifFail(int xP, int yP) {
    	return ((x == xP ) && (y == yP)); 
    }
    
    /**
     * maze init
     * @param map - input data
     * @param p - instance of pacman class
     */
    public void init(Thing map[][], Pacman p) {
    	maze = map;
    	this.p = p;
    }
    
    /**
     * describe monsters movement
     */
    private void move() {
       	direction = strategy.SelectDirection(maze, x, y, p.getX(), p.getY());
       	if (direction == 0)
       		y--;
       	if (direction == 1)
       		x++;
		if (direction == 2)
			y++;
		if (direction == 3) 
			x--;
    }
}